package com.geekbang.work6;

import com.geekbang.work6.mapper.BookOrderMapper;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nhsoft.lul
 */
@Service
@Transactional
@ShardingTransactionType(TransactionType.XA)
public class BookOrderService {

    @Resource
    private BookOrderMapper bookOrderMapper;

    public List<BookOrder> list(){
        return bookOrderMapper.list();
    }

    public void save(){
        bookOrderMapper.save(System.currentTimeMillis(), 1L);
        bookOrderMapper.save(System.currentTimeMillis(), 2L);
    }

    public void delete(){
        bookOrderMapper.delete();
    }

    public void saveRollback(){
        bookOrderMapper.save(System.currentTimeMillis(), 1L);
        bookOrderMapper.save(System.currentTimeMillis(), 2L);
        int i = 1/0;
    }
}
